
* Formatting
graph set window fontface "Times New Roman"	// use Times New Roman as the default font for Graph window
// 	 graph set window fontface default 			// use this to restore to factury setting if preferred later

set scheme s1mono



********************************************************************
*************** Figure A.5 ***************

*** Prepare the data
use "${ddata}cleaned_data_wACSweight.dta", clear 

keep qs2_* treatment uuid white age male college married working_ft child_under_6 child_under_18 lincome sce current_censusdiv weight weight_ACS donation_fo donation_so donation_so_l_fo ///
	original_gap0 original_gap1 original_gap2 original_gap3 original_gap4 original_gap5

rename uuid uuid_w2
keep if uuid_w2!=""
foreach v in white age male college married working_ft child_under_6 child_under_18 lincome sce current_censusdiv donation_fo donation_so donation_so_l_fo{
	rename `v' `v'_oct2021
}

cap drop _merge	
merge 1:1 uuid_w2 using "${rdata}followup_surveydata.dta"

gen wave3 = uuid_w3~=""
sum wave3

replace treatment = 0 if HQs1r3==1 & treatment==. 
replace treatment = 1 if HQs1r3==. & treatment==. 


assert qs2_1 == recommend_timeoff1_w2 if qs2_1~=.
assert qs2_2 == recommend_timeoff2_w2 if qs2_2~=.
assert qs2_3 == recommend_timeoff3_w2 if qs2_3~=.
assert qs2_4 == recommend_timeoff4_w2 if qs2_4~=.
assert qs2_5 == recommend_timeoff5_w2 if qs2_5~=.

drop qs2_*

rename recommend_stayhome 	 recommend_timeoff0 
rename recommend_stayhome_w2 recommend_timeoff0_w2


forvalues i = 0/5{

	cap drop consistent_sample`i'
	gen 	 consistent_sample`i' = (recommend_timeoff`i'!=. & recommend_timeoff`i'_w2!=. & weight_ACS!=.)

	rename recommend_timeoff`i' 	qs2_`i'
	rename recommend_timeoff`i'_w2  qs2_`i'_w2

} 

keep uuid_w2 uuid_w3 sce_oct2021 treatment   qs*   weight_ACS

save "${ddata}temp", replace



*** May2023 subfigure

drop if uuid_w3 == ""

forvalues i=0(1)5 {

	reg qs2_`i' treatment [aweight=weight_ACS] , robust

	matrix q`i' = r(table)

	gen p_`i'= q`i'[4,1]

}

keep  uuid_w3  qs2_* p_* treatment sce weight_ACS

reshape long qs2_ p_,  i( uuid_w3 sce treatment weight_ACS) j(questions)

rename qs2_ answers

rename p_ p_value

collapse (mean) mean= answers p_value (sd) sd=answers (count) n=answers [aweight=weight_ACS], by(question treatment)


generate hiwrite = mean + invttail(n-1,0.025)*(sd / sqrt(n))
generate lowrite = mean - invttail(n-1,0.025)*(sd / sqrt(n))

generate q_t = 1    if question==0&treatment==0
replace  q_t = 2    if question==0&treatment==1
replace  q_t = 4    if question==1&treatment==0
replace  q_t = 5    if question==1&treatment==1
replace  q_t = 7    if question==2&treatment==0
replace  q_t = 8    if question==2&treatment==1
replace  q_t = 10   if question==3&treatment==0
replace  q_t = 11   if question==3&treatment==1
replace  q_t = 13   if question==4&treatment==0
replace  q_t = 14   if question==4&treatment==1
replace  q_t = 16   if question==5&treatment==0
replace  q_t = 17   if question==5&treatment==1

sort q_t

gen 	position=1.5  if question==0
replace position=4.5  if question==1
replace position=7.5  if question==2
replace position=10.5 if question==3
replace position=13.5 if question==4
replace position=16.5 if question==5

gen _plotp =""

forvalues i=0(1)5 {

	egen max_`i'=max(mean) if question==`i'
	gen  ppv_`i'=p_value   if question==`i'
	egen pv_`i' =max(ppv_`i')
	local p`i': display %4.3f pv_`i' 			 //store p-value with correct formating in local macro
	replace _plotp = "p=`p`i''" if question==`i' //store p-value with brackets as string variable

}

gen y=.

forvalues i=0(1)5 {

	replace y=max_`i'+5 if question==`i'

}


twoway (bar mean q_t if treatment==0, color(navy%30) ) ///
	(bar mean q_t if treatment==1, color(navy%90) ) ///
	(scatter  y position, msym(none) mlab(_plotp) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(rcap hiwrite lowrite q_t), ///
	legend( order(1 "Control" 2 "Treatment" ) ) ///
	xlabel( 1.5 "Mother reject offer" 4.5 "15% less" 7.5 "Same" 10.5 "15% more" 13.5 "30% more" 16.5 "50% more", noticks  labsize(vsmall)) ///
	ylabel(0(10)80,labsize(small)) yscale(r(0 70)) ///
	xtitle("   Mother makes", size(small)) legend(region(lstyle(none)) size(vsmall)) ytitle("Probability recommends conservative action", size(small)) title("May 2023", size(small)) 

graph save "${o}f1_may23", replace






*** Oct2021 subfigure		
**** follow-up sample with original data**

use "${ddata}temp", replace

drop qs2_0-qs2_5
drop if uuid_w3==""

forvalues i=0(1)5 {

	reg qs2_`i'_w2 treatment [aweight=weight_ACS], robust

	matrix q`i' = r(table)
	gen p_`i'= q`i'[4,1]

	rename qs2_`i'_w2 qs2_`i'

}

keep  uuid_w3  qs2_* p_* treatment sce weight_ACS

reshape long qs2_ p_,  i( uuid_w3 sce treatment weight_ACS) j(questions)

rename qs2_ answers

rename p_ p_value

collapse (mean) mean= answers p_value (sd) sd=answers (count) n=answers [aweight=weight_ACS], by(question treatment)

generate hiwrite = mean + invttail(n-1,0.025)*(sd / sqrt(n))
generate lowrite = mean - invttail(n-1,0.025)*(sd / sqrt(n))

generate q_t = 1    if question==0&treatment==0
replace  q_t = 2    if question==0&treatment==1
replace  q_t = 4    if question==1&treatment==0
replace  q_t = 5    if question==1&treatment==1
replace  q_t = 7    if question==2&treatment==0
replace  q_t = 8    if question==2&treatment==1
replace  q_t = 10   if question==3&treatment==0
replace  q_t = 11   if question==3&treatment==1
replace  q_t = 13   if question==4&treatment==0
replace  q_t = 14   if question==4&treatment==1
replace  q_t = 16   if question==5&treatment==0
replace  q_t = 17   if question==5&treatment==1

sort q_t

gen 	position=1.5  if question==0
replace position=4.5  if question==1
replace position=7.5  if question==2
replace position=10.5 if question==3
replace position=13.5 if question==4
replace position=16.5 if question==5



gen _plotp =""

forvalues i=0(1)5 {

	egen max_`i'= max(mean) if question==`i'

	gen ppv_`i' = p_value   if question==`i'			
	egen pv_`i' = max(ppv_`i')
	local p`i': display %4.3f pv_`i' 			 //store p-value with correct formating in local macro
	replace _plotp = "p=`p`i''" if question==`i' //store p-value with brackets as string variable

}



gen y=.

forvalues i=0(1)5 {

	replace y=max_`i'+5 if question==`i'

}



twoway (bar mean q_t if treatment==0, color(navy%30) ) ///
	(bar mean q_t if treatment==1, color(navy%90) ) ///
	(scatter  y position, msym(none) mlab(_plotp) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(rcap hiwrite lowrite q_t), ///
	legend( order(1 "Control" 2 "Treatment" ) ) ///
	xlabel( 1.5 "Mother reject offer" 4.5 "15% less" 7.5 "Same" 10.5 "15% more" 13.5 "30% more" 16.5 "50% more", noticks  labsize(vsmall)) ///
	ylabel(0(10)80,labsize(small)) yscale(r(0 70)) ///
	xtitle("   Mother makes", size(small)) legend(region(lstyle(none)) size(vsmall)) ytitle("Probability recommends conservative action", size(small)) title("October 2021", size(small)) 

graph save "${o}f1_oct21", replace




*** Combine	
grc1leg  "${o}f1_oct21.gph" "${o}f1_may23.gph",  ycommon legendfrom("${o}f1_oct21.gph") 
graph export "${o}follow_up_f1.pdf", replace

erase "${o}f1_oct21.gph"
erase "${o}f1_may23.gph"
